package com.peoit.honeycomb.rest;

import java.util.logging.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.peoit.honeycomb.application.ProjectNoticeApplication;
import com.peoit.honeycomb.domain.exception.ProjectNotExistException;
import com.peoit.honeycomb.domain.exception.UserNotExistException;
import com.peoit.honeycomb.dto.CommonResultDto;
import com.peoit.honeycomb.dto.ProjectNoticeDto;

@Controller
@RequestMapping("/api/notice")
public class ProjectNoticeResource extends BaseResource {
	Logger logger = Logger.getLogger(UserResource.class.getName());

	@Autowired
	ProjectNoticeApplication projectNoticeApplication;

	@RequestMapping(value = "/publishnotice", method = RequestMethod.POST)
	public @ResponseBody CommonResultDto publishNotice(ProjectNoticeDto dto) {
		CommonResultDto result = new CommonResultDto();
		try {
			projectNoticeApplication.publishProjectNotice(dto);
			result.setResult_code("200");
			result.setReason("success");
		} catch (ProjectNotExistException e) {
			result.setResult_code("402");
			result.setReason("project not exist");
		} catch (UserNotExistException e) {
			result.setResult_code("401");
			result.setReason("user not exist");
		} catch (Exception e) {
			result.setResult_code("500");
			result.setReason("Internal error");
		}
		return result;
	}

	@RequestMapping(value = "/listnotice", method = RequestMethod.POST)
	public @ResponseBody CommonResultDto listNotice(ProjectNoticeDto dto) {
		CommonResultDto result = new CommonResultDto();
		try {
			result.setResult_code("200");
			result.setReason("success");
			result.setResult(projectNoticeApplication.findProjectNotice(dto));
		} catch (Exception e) {
			result.setResult_code("500");
			result.setReason("Internal error");
		}
		return result;
	}

}
